# Check for CMAKE version
cmake_minimum_required (VERSION 2.6)


Project(Alcor)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
include(AlcorMacroUtils)

set(Alcor_BASE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.. CACHE PATH "Alcor base path")
set(Alcor_BIN_PATH ${Alcor_BASE_PATH}/alcor.bin) 
set(Alcor_LIB_PATH ${Alcor_BASE_PATH}/alcor.lib)
set(Alcor_SRC_PATH ${Alcor_BASE_PATH}/alcor)
set(Alcor_APPS_PATH ${Alcor_BASE_PATH}/alcorApps)
set(Alcor_EXT_PATH ${Alcor_BASE_PATH}/alcor.extern)


include_directories(${Alcor_BASE_PATH})
include_directories(${Alcor_EXT_PATH})
link_directories(${Alcor_LIB_PATH}/${CMAKE_SYSTEM_NAME}/${CMAKE_BUILD_TYPE})


##visual studio specific flags
if(WIN32)
    if(MSVC)
	option(STATIC_RUNTIME "Set whenever use static or dynamic runtime libraries for linking (/MT or /Md flags)" ON)
        if (STATIC_RUNTIME)
	    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
	    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
	endif (STATIC_RUNTIME)
    endif(MSVC)
endif(WIN32)

option(Alcor_BUILD_SHARED_LIBS "Enable shared libraries build" OFF)
if (Alcor_BUILD_SHARED_LIBS)
    set (LIB_BUILD_CONTROL SHARED)
endif (Alcor_BUILD_SHARED_LIBS)


set (BOOST_STATIC ON CACHE BOOL "Enable to use static version of Boost libraries")
if (BOOST_STATIC)
    set (Boost_USE_STATIC_LIBS TRUE)
else (BOOST_STATIC)
    set (Boost_USE_STATIC_LIBS FALSE)
endif (BOOST_STATIC)

find_package(Boost COMPONENTS date_time filesystem system thread regex)

if (Boost_FOUND)
   include_directories(${Boost_INCLUDE_DIR})
   #link_directories(${Boost_LIBRARY_DIRS})
else (Boost_FOUND)
   set(BOOST_ROOT "BOOST_ROOT-NOTFOUND" CACHE PATH "Boost root folder")
endif (Boost_FOUND)

find_package(OpenCV COMPONENTS CV CXCORE CVAUX HIGHGUI)
if (OpenCV_FOUND)
    include_directories(${OpenCV_INCLUDE_DIRS})
    #link_directories(${OpenCV_LINK_DIRECTORIES})
else (OpenCV_FOUND)
    set(OpenCV_ROOT_DIR "OpenCV_ROOT_DIR-NOTFOUND" CACHE PATH "OpenCV root folder")
endif (OpenCV_FOUND)


option (WX_MONO "Enable to use monolithic version of wx libraries" ON)

if (WX_MONO)
    set (wxWidgets_USE_LIBS mono gl)
else (WX_MONO)
    set (wxWidgets_USE_LIBS base core gl net)
endif (WX_MONO)

find_package(wxWidgets)

if (wxWidgets_FOUND)
    include_directories(${wxWidgets_INCLUDE_DIRS})
endif(wxWidgets_FOUND)

find_package(Threads)

find_package(JPEG)

if (JPEG_FOUND)
    include_directories(${JPEG_INCLUDE_DIR})
endif (JPEG_FOUND)
    
if (WIN32)
    SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Alcor_BIN_PATH}/${CMAKE_SYSTEM_NAME})
    SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Alcor_LIB_PATH}/${CMAKE_SYSTEM_NAME})
    SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Alcor_LIB_PATH}/${CMAKE_SYSTEM_NAME})
endif (WIN32)

if (UNIX)
    SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Alcor_BIN_PATH}/${CMAKE_SYSTEM_NAME}/${CMAKE_BUILD_TYPE})
    SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Alcor_LIB_PATH}/${CMAKE_SYSTEM_NAME}/${CMAKE_BUILD_TYPE})
    SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Alcor_LIB_PATH}/${CMAKE_SYSTEM_NAME}/${CMAKE_BUILD_TYPE})
endif (UNIX)

add_subdirectory(lib)
add_subdirectory(apps)

option (Alcor_BUILD_SAMPLES "Set whenever to build or not sample applications" ON)
if (Alcor_BUILD_SAMPLES)
    add_subdirectory(samples)
endif (Alcor_BUILD_SAMPLES)
